/*最大子列和问题*/

#include <stdio.h>
int max_seq_sum(int k, int a[]) {
    int max_sum, curr_sum;
    curr_sum = 0;
    max_sum = 0;
    for (int i = 0; i < k; i++) {
        curr_sum += a[i];
        if (curr_sum > max_sum) {
            max_sum = curr_sum;
        } else if (curr_sum < 0) {
            curr_sum = 0;
        }
    }
    return max_sum;
}
int main(int argc, char *argv[]) {
    int k;
    scanf("%d", &k);
    int a[k];
    for (int i = 0; i < k; i++) {
        scanf("%d", &a[i]);
    }
    printf("%d\n", max_seq_sum(k, a));
    return 0;
}